package qqq.aop.aspectJ;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Order(3)
@Component
@Aspect
public class MyAspect {

    @Pointcut("execution(public * qqq.aop.User.*(..))")
    public void point() {
    }

    //环绕通知
    @Around("point()")
    public Object aroundMethod(JoinPoint joinPoint) {

        Object result = null;
        try {
            System.out.println("环绕通知 START");
            result = ((ProceedingJoinPoint) joinPoint).proceed();
        } catch (Throwable e) {
            throw new RuntimeException(e);
        } finally {
            System.out.println("环绕通知 END");
        }
        return result;
    }

    //前置通知
    @Before("point()")
    public void beforeMethod(JoinPoint joinPoint) {
        System.out.println("前置通知");
    }

    //后置通知
    @After("point()")
    public void afterMethod(JoinPoint joinPoint) {
        System.out.println("后置通知");
    }

    //正常后置通知
    @AfterReturning(value = "point()", returning = "result")
    public void afterReturningMethod(JoinPoint joinPoint, Object result) {
        System.out.println("正常后置通知");

    }

    //异常后置通知
    @AfterThrowing(value = "point()", throwing = "e")
    public void afterReturningMethod(JoinPoint joinPoint, Throwable e) {
        System.out.println("异常后置通知");
    }


}
